//
//  ProvideAPI.swift
//  ShareUmbrella
//
//  Created by niupark on 2017/9/17.
//  Copyright © 2017年 尧尚信息科技. All rights reserved.
//

import Moya
import YSKit

public enum ProvideAPI: YSTargetRequestable {
    
    case startAcceptHelpAction(token: String)
    case stopAcceptHelpAction(token: String)
    case acceptHelpAction(token: String, helpid: String)
    case refuseHelpAction(token: String, helpid: String)
    case terminatHelpAction(token: String, helpid: String)
    case getMyLastCommentted(token: String)

    
    /// 请求的URL分别写在API内部
    fileprivate struct RequestURL {
        // MARK: Market
        static let startAcceptHelpAction = "/u4uapi/Index/StartAcceptHelpAction"
        static let stopAcceptHelpAction = "/u4uapi/Index/StopAcceptHelpAction"
        static let acceptHelpAction = "/u4uapi/Index/AcceptHelpAction"
        static let refuseHelpAction = "/u4uapi/Index/RefuseHelpAction"
        static let terminatHelpAction = "/u4uapi/Index/TerminatHelpAction"
        static let getMyLastCommentted = "/u4uapi/Index/GetMyLastCommentted"

    }
    
    public var api: YSTargetRequest {
        
        switch self {
        case .startAcceptHelpAction(let token):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            return YSTargetRequest(path: RequestURL.startAcceptHelpAction,
                                   method: .post,
                                   parameters: parameters
            )
            
            
        case .stopAcceptHelpAction(let token):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            return YSTargetRequest(path: RequestURL.stopAcceptHelpAction,
                                   method: .post,
                                   parameters: parameters
            )
            
        case .acceptHelpAction(let token, let helpid):
            var parameters: [String: Any] = [:]
            parameters["helpid"] = helpid
            parameters["token"] = token
            return YSTargetRequest(path: RequestURL.acceptHelpAction,
                                   method: .post,
                                   parameters: parameters
        )
        
        case .refuseHelpAction(let token, let helpid):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            parameters["helpid"] = helpid
            return YSTargetRequest(path: RequestURL.refuseHelpAction,
                                   method: .post,
                                   parameters: parameters
            )
        case .terminatHelpAction(let token, let helpid):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            parameters["helpid"] = helpid
            return YSTargetRequest(path: RequestURL.terminatHelpAction,
                                   method: .post,
                                   parameters: parameters
            )
            
        case .getMyLastCommentted(let token):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            return YSTargetRequest(path: RequestURL.getMyLastCommentted,
                                   method: .post,
                                   parameters: parameters
            )
            
        }
        
        
    }
    
    public var path: String {
        return self.api.path
    }
    // 获取基本的url，每次发生地址变更时，替换这个url
    public var baseURL: URL {
        
        return self.api.baseURL ?? URL(string: HostManager.kMainHost)!
    }
    public var method: Moya.Method {
        return self.api.method
    }
    public var parameters: [String: Any]? {
        return self.api.parameters
    }
    public var sampleData: Data {
        return self.api.sampleData
    }
    public var task: Task {
        return self.api.task
    }
    public var validate: Bool {
        return false
    }
    public var parameterEncoding: Moya.ParameterEncoding {
        return self.api.parameterEncoding
    }
}
